package com.dfy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dfy.dto.SpotSearchRequest;
import com.dfy.entity.Spot;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface SpotMapper extends BaseMapper<Spot> {
    @Select("SELECT s.* FROM spots s " +
           "JOIN user_favorites uf ON s.id = uf.spot_id " +
           "WHERE uf.user_id = #{userId} " +
           "LIMIT #{offset}, #{limit}")
    List<Spot> getUserFavorites(@Param("userId") Long userId, 
                               @Param("offset") int offset, 
                               @Param("limit") Integer limit);

    @Select("SELECT COUNT(*) > 0 FROM user_favorites " +
           "WHERE user_id = #{userId} AND spot_id = #{spotId}")
    boolean isFavorite(@Param("userId") Long userId, @Param("spotId") Long spotId);

    @Select("SELECT * FROM spots WHERE id = #{id}")
    Spot findById(@Param("id") Long id);

    void addFavorite(Long userId, Long spotId);
    void removeFavorite(Long userId, Long spotId);
    void deleteFavoritesBySpotId(Long spotId);
    List<Spot> getSpotsByCategory(String category);
    List<Spot> searchSpots(SpotSearchRequest request);
    Spot selectSpotById(@Param("id") Long id);
    List<Spot> selectSpotsByIds(@Param("spotIds") String spotIds);
} 